package com.example.controller;

import com.example.entity.Student;
import com.example.service.StudentService;
import com.example.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
@Tag(name = "学生管理")
public class StudentController {
    @Resource
    private StudentService studentService;

    @GetMapping("/student-no/{studentNo}")
    public Student getByStudentNo(@PathVariable String studentNo) {
        return studentService.getByStudentNo(studentNo);
    }

    @PutMapping("/{id}/physical-exam")
    public boolean updatePhysicalExamData(@PathVariable Long id, @RequestParam String physicalExamData) {
        return studentService.updatePhysicalExamData(id, physicalExamData);
    }

    @PostMapping("/import/{schoolId}")
    @Operation(summary = "导入学生数据")
    public Result<String> importStudents(@PathVariable Long schoolId, @RequestParam("file") MultipartFile file) {
        try {
            studentService.importStudentsFromExcel(schoolId, file);
            return Result.success("学生数据导入成功");
        } catch (Exception e) {
            return Result.error("导入失败：" + e.getMessage());
        }
    }
} 